#include "thread.h"
#define SALT_LENGTH 16

void generateRandomSalt(char *salt, int length) {
    const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int charsetLength = sizeof(charset) - 1;

    for (int i = 0; i < length; ++i) {
        int index = rand() % charsetLength;
        salt[i] = charset[index];
    }
    salt[length] = '\0';
}

int generateFormattedSalt(char *formattedSalt, int length) {
    if (length < 3) {
        printf("Error: Salt length must be at least 3.\n");
        return -1;
    }

    char salt[SALT_LENGTH + 1];
    generateRandomSalt(salt, SALT_LENGTH);

    snprintf(formattedSalt,length, "$6$%s$", salt);
    return 0;
}
